package com.example.messagemodule.listener;

import com.hyphenate.EMConnectionListener;
import com.hyphenate.EMError;
import com.yilijk.base.utils.ALog;

import org.greenrobot.eventbus.EventBus;

public class IMConnectionListener implements EMConnectionListener {
    @Override
    public void onConnected() {
        ALog.e("IMConnectionListener","onConnected");
        EventBus.getDefault().post(new EventBusMessageWrap(null,MessageListenerType.IMLoginSuccess));
    }

    @Override
    public void onDisconnected(int errorCode) {  if (errorCode == EMError.USER_REMOVED) {
        //用户被删
        ALog.d("IMConnectionListener", "用户被删");
    } else if (errorCode == EMError.USER_LOGIN_ANOTHER_DEVICE) {
        //账户在另外一台设备登录
        ALog.d("IMConnectionListener", "账户在另外一台设备登录");
    } else if (errorCode == EMError.SERVER_SERVICE_RESTRICTED) {
        //IM功能限制
        ALog.d("IMConnectionListener", "IM功能限制");
    } else if (errorCode == EMError.USER_KICKED_BY_CHANGE_PASSWORD) {
        //用户修改密码
        ALog.d("IMConnectionListener", "用户修改密码");
    } else if (errorCode == EMError.USER_KICKED_BY_OTHER_DEVICE) {
        //用户被其他设备踢掉
        ALog.d("IMConnectionListener", "用户被其他设备踢掉");
    }
        ALog.e("IMConnectionListener","onDisconnected");
        EventBus.getDefault().post(new EventBusMessageWrap(null,MessageListenerType.IMLoginError));
    }
}
